
export interface AssertUsedParam {
    skips: string[];
}

export interface TmpDirParam {
    tmp_dirs: string[];
}

export interface FuncNameParam {
    function_names: string[];
}

export interface CheckExceptionParam {
    check_typed_exception: boolean;
}

export interface BadProtoParam {
    bad_protocol_versions: string[];
}

export interface ShellInjectionParam {
    subprocess?: string[];
    shell?: string[];
    no_shell?: string[];
}

export interface InnerBanditConfig {
    targets?: string[];
    exclude_dirs?: string[];
    tests?: string[];
    skips?: string[];
    assert_used?: AssertUsedParam;
    hardcoded_tmp_directory?: TmpDirParam;
    password_config_option_not_marked_secret?: FuncNameParam;
    try_except_pass?: CheckExceptionParam;
    execute_with_run_as_root_equals_true?: FuncNameParam;
    try_except_continue?: CheckExceptionParam;
    ssl_with_bad_version?: BadProtoParam;
    shell_injection?: ShellInjectionParam;
}

export interface ToolConfig {
    bandit?: InnerBanditConfig;
}

export interface BanditConfig {
    tool?: ToolConfig;
}

export function removeUnNeedCfg(cfg: BanditConfig): BanditConfig {
    if (cfg.tool == undefined) {
        return cfg;
    }
    if (cfg.tool.bandit == undefined) {
        return cfg;
    }
    if (cfg.tool.bandit.tests == undefined) {
        return cfg;
    }
    if (cfg.tool.bandit.tests.includes("B101") == false) {
        delete cfg.tool.bandit.assert_used;
    }
    if (cfg.tool.bandit.tests.includes("B108") == false) {
        delete cfg.tool.bandit.hardcoded_tmp_directory;
    }
    if (cfg.tool.bandit.tests.includes("B109") == false) {
        delete cfg.tool.bandit.password_config_option_not_marked_secret;
    }
    if (cfg.tool.bandit.tests.includes("B110") == false) {
        delete cfg.tool.bandit.try_except_pass;
    }
    if (cfg.tool.bandit.tests.includes("B111") == false) {
        delete cfg.tool.bandit.execute_with_run_as_root_equals_true;
    }
    if (cfg.tool.bandit.tests.includes("B112") == false) {
        delete cfg.tool.bandit.try_except_continue;
    }
    if (cfg.tool.bandit.tests.includes("B502") == false) {
        delete cfg.tool.bandit.ssl_with_bad_version;
    }
    let match = false;
    for (const ruleId of ["B602", "B603", "B604", "B605", "B606", "B607", "B609"]) {
        if (cfg.tool.bandit.tests.includes(ruleId)) {
            match = true;
            break;
        }
    }
    if (!match) {
        delete cfg.tool.bandit.shell_injection;
    }
    return cfg;
}